package me.zhengjie.modules.quartz.task;

import com.qiaofang.applet.service.member.service.MemberSubscribeService;
import com.qiaofang.applet.service.other.domain.Corporation;
import com.qiaofang.applet.service.other.service.CorporationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
public class OpenEstateTask {

    @Autowired
    private CorporationService corporationService;

    @Autowired
    private MemberSubscribeService memberSubscribeService;

    public void run() {
        log.info("OpenEstateTask run start");
        Corporation corporation = new Corporation();
        corporation.setDeleted(Boolean.FALSE);
        corporation.setV20Flag(Boolean.FALSE);
        Iterable<Corporation> list = corporationService.findAll(Example.of(corporation));
        list.forEach(item -> {
            String corporationCode = item.getCorporationCode();
            log.info("开始处理集团:{}的订阅短信，开始时间:{}", corporationCode, new Date());
            long begin = System.currentTimeMillis();
            memberSubscribeService.sendMessagesTask(corporationCode);
            long end = System.currentTimeMillis();
            log.info("完成处理集团:{}的订阅短信，耗时:{}", corporationCode , (end - begin));
        });
    }
}
